package com.fetch.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JTextField;

public class FileBrowserActionListener implements ActionListener {

    private JButton fileBrowser;
    private JTextField directory;
    private JFileChooser fileChooser;
    
    public FileBrowserActionListener(JButton fileBrowser, JTextField directory) {
        super();
        this.fileBrowser = fileBrowser;
        this.directory = directory;
        this.fileChooser = new JFileChooser();
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
        int selectState  = fileChooser.showOpenDialog(fileBrowser.getParent());
        if(selectState == JFileChooser.APPROVE_OPTION){
            File f = fileChooser.getSelectedFile();
            directory.setText(f.getAbsolutePath());
        }
        
    }

}
